package com.probiz.estore.system.dao.impl;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.probiz.estore.system.dao.AppMenuDao;
import com.probiz.estore.common.model.system.AppMenu;
import com.probiz.estore.common.model.system.AppResource;
import com.probiz.estore.core.dao.impl.HibernateGenericDaoImpl;
import com.probiz.estore.core.model.BaseObject;

/**
 * Dao implementation for AppMenu.
*/
public class AppMenuDaoImpl extends HibernateGenericDaoImpl<AppMenu> implements AppMenuDao {
	protected void initFilterHqlMap() {
		filterHqlMap.put(BaseObject.FilterHqlName.DEFAULT, "from AppMenu s where s.belongTo=? order by s.url");
	}
	
	public boolean isPatternExist(String url, Integer excludeMenuId){
		if(StringUtils.isBlank(url))
			return false;
		String hql = "from AppMenu s where url=?";
		
		if(excludeMenuId!=null){
			hql += " and menuId!=?";
			return this.countByHql(hql, url, excludeMenuId)>0;
		}
		
		return this.countByHql(hql, url)>0;
	}
	
	@Override
	public List<AppMenu> listAll(){
		return this.listAllOrdered("url", false);
	}
}
